package com.pt.dto.response;

import lombok.Data;
import java.time.LocalDateTime;

@Data
public class InvitationResponse {
    private Long id;
    private String code;
    private Long creatorId;
    private Long usedBy;
    private String usedByUsername;
    private Integer status;
    private Boolean used;
    private Boolean isUsed;
    private LocalDateTime createdTime;
    private LocalDateTime createTime;
    private LocalDateTime usedTime;
    private LocalDateTime expireTime;
    
    /**
     * 从Invitation实体构建响应对象
     */
    public static InvitationResponse fromEntity(com.pt.entity.Invitation invitation) {
        InvitationResponse response = new InvitationResponse();
        response.setId(invitation.getId());
        response.setCode(invitation.getCode());
        response.setCreatorId(invitation.getCreatorId());
        response.setUsedBy(invitation.getUsedBy());
        response.setStatus(invitation.getStatus());
        response.setUsed(invitation.getStatus() == 1);
        response.setIsUsed(invitation.getStatus() == 1);
        response.setCreatedTime(invitation.getCreatedTime());
        response.setCreateTime(invitation.getCreatedTime());
        response.setUsedTime(invitation.getUsedTime());
        response.setExpireTime(invitation.getExpireTime());
        // 用户名需要在service层单独查询并设置
        return response;
    }
    
    /**
     * 从Invitation实体构建响应对象，并设置用户名
     */
    public static InvitationResponse fromEntity(com.pt.entity.Invitation invitation, String usedByUsername) {
        InvitationResponse response = fromEntity(invitation);
        response.setUsedByUsername(usedByUsername);
        return response;
    }
} 